﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace MegavaniaX.World
{
    /// <summary>
    /// A generic Tile in the game world.  This is a 16x16 tile that represents, essentially, the
    /// backdrop.  Tiles do not move, though they may be animated.
    /// </summary>
    public class Tile
    {      
        /// <summary>
        /// Absolute X/Y coordinates, for rendering and collision purposes
        /// </summary>
        [ContentSerializerIgnore]
        private Vector2 _coordinates;

        public Vector2 Coordinates
        {
            get
            {
                if (!CoordsInit)
                    _coordinates = new Vector2(X * 16.0f, Y * 16.0f);
                return _coordinates;
            }
        }

        [ContentSerializerIgnore]
        public bool CoordsInit = false;

        [ContentSerializerIgnore]
        public Int32 Width = 16;

        [ContentSerializerIgnore]
        public Int32 Height = 16;

        //public Texture2D Texture;
        //public Rectangle SourceRectangle;
        public TileTexture tileTexture;
        public int X;
        public int Y;
        public bool IsSolid;
        public bool IsLadder;

        public Tile()
        {

        }            

        public Texture2D CurrentTexture(UInt64 frameCounter)
        {            
            return tileTexture.Texture;
        }

        public Rectangle CurrentTextureRectangle(UInt64 frameCounter)
        {
            int idx = (int)Math.Floor(frameCounter / 20.0f) % tileTexture.SourceRectangles.Count();
            return tileTexture.SourceRectangles[idx];
        }

    }
}
